package evostar.dao;

import evostar.model.SeckillGoods;
import evostar.VO.GoodsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface GoodsDAO {

    @Select("select * from seckill_goods as sg left join goods on sg.goods_id = goods.id")
    List<GoodsVO> listGoodsVO();

    @Select("select * from seckill_goods as sg left join goods on sg.goods_id = goods.id where goods.id = #{goodsId}")
    GoodsVO getGoodsByGoodsId(int goodsId);

    @Update("update seckill_goods set seckill_stock = seckill_stock - 1 where goods_id = #{goodsId} and seckill_stock > 0")
    int reduceStock(SeckillGoods g);
}
